<form action="cmsWebFile/doUpload?callbackType=closeCurrent&navTabId=cmsWebFile/list" method="post" autocomplete="off" enctype="multipart/form-data" class="pageForm required-validate" onsubmit="return iframeCallback(this, dialogAjaxDone)">
    <input type="hidden" name="_csrf" value="<@tools.csrfToken admin=true/>"/>
    <div class="pageFormContent" layoutH>
        <dl class="nowrap">
            <dt><@t.page 'file'/>:</dt>
            <dd>
                <input type="hidden" name="path" value="${path!}"/>
                <input type="file" name="files" class="required" size="30" multiple="multiple"/>
                <label class="overwrite hide"><input type="checkbox" name="overwrite" checked="checked"><@t.page 'upload.overwrite'/></label>
            </dd>
        </dl>
    </div>
    <div class="formBar">
        <ul>
            <li><button type="submit" class="buttonActive" title="ctrl+s"><@t.page 'upload'/></button></li>
            <li><button type="button" class="button close"><@t.page 'button.close'/></button></li>
        </ul>
    </div>
</form>
<script>
$(".pageFormContent",$.pdialog.getCurrent()).on("change","input[type=file]",function(){
    if($(this).length && $(this)[0].files){
        var fileNames = [];
        $.each($(this)[0].files, function(i, file) {
            fileNames.push(file.name);
        });
        $.ajax({
            url:'cmsWebFile/check',
            type: 'POST',
            dataType: "json",
            async: false,
            data: {
                fileNames : fileNames,
                path : $("input[name=path]",$.pdialog.getCurrent()).val(),
                _csrf : $("input[name=_csrf]",$.pdialog.getCurrent()).val()
            },
            success: function (result) {
                if(true==result){
                    $('.overwrite').show();
                } else {
                    $('.overwrite').hide();
                }
            }
        });
    }
});
</script>